/*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package managedBean.TX.tta;

    import Helper.Helper_Survey;
    import entity.Places;
    import java.util.ArrayList;
    import java.util.List;
    import javax.ejb.EJB;
    import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
    import javax.faces.bean.ViewScoped;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import session.TX.SurveySBRemote; 

    @ManagedBean(name = "surveyMB")
    @RequestScoped
    public class SurveyMB {

        @EJB
        SurveySBRemote sBean;
        private Integer month = 1;
        private Integer year = 2011;
        private List<Double> resultList = new ArrayList<Double>();
        List<Helper_Survey> results = new ArrayList<Helper_Survey>();


        /** Creates a new instance of OMPIPMB */
        public SurveyMB() {
        }

        public Double getOutletOverallResult (long outletid, int month, int year) {
            Places place = sBean.getSpecificPlace(outletid);
            double result = sBean.getOverallResult(place, month, year);
            return result;
        }

        public Double getOutletAmbienceResult (long outletid, int month, int year) {
            Places place = sBean.getSpecificPlace(outletid);
            double result = sBean.getAmbienceResult(place, month, year);
            return result;
        }

        public Double getOutletServiceResult (long outletid, int month, int year) {
            Places place = sBean.getSpecificPlace(outletid);
            double result = sBean.getServiceResult(place, month, year);
            return result;
        }

        public Double getOutletFoodResult (long outletid, int month, int year) {
            Places place = sBean.getSpecificPlace(outletid);
            double result = sBean.getFoodResult(place, month, year);
            return result;
        }

        public Double getOutletPriceResult (long outletid, int month, int year) {
            Places place = sBean.getSpecificPlace(outletid);
            double result = sBean.getPricingResult(place, month, year);
            return result;
        }

        public Integer getNoOfReviews() {
            int month1 = month - 1;
            long out = getOutletId();
            Places place = sBean.getSpecificPlace(out);
            int result = sBean.getNoOfReviews(place, month1, year);
            return result;
        }

        public List<Helper_Survey> getResults() {
            return results;
        }

        public void setResults(List<Helper_Survey> results) {
            this.results = results;
        }

        public List<Helper_Survey> getResult() {

            List<Helper_Survey> output = new ArrayList<Helper_Survey>();
            int month1 = month - 1;
            Double oaResult = sBean.getAmbienceResultAll(month1, year);
            long o = getOutletId();
            Places place = sBean.getSpecificPlace(o);
            System.out.println("TES" + place.getPlaceName());
            System.out.println("SMLJ " + getOutletId());
            Double aResult = sBean.getAmbienceResult(place, month1, year);
            Helper_Survey temp = new Helper_Survey("Ambience", aResult, oaResult);
            output.add(temp);
            Double foodResult = getOutletFoodResult(getOutletId(), month1, year);
            Double overallFoodResult = sBean.getFoodResultAll(month1, year);
            Helper_Survey temp1 = new Helper_Survey("Food", foodResult, overallFoodResult);
            output.add(temp1);
            Double priceResult = getOutletPriceResult(getOutletId(), month1, year);
            Double overallPriceResult = sBean.getPricingResultAll(month1, year);
            Helper_Survey temp2 = new Helper_Survey("Price", priceResult, overallPriceResult);
            output.add(temp2);
            Double serviceResult = getOutletServiceResult(getOutletId(), month1, year);
            Double overallServiceResult = sBean.getServiceResultAll(month1, year);
            Helper_Survey temp3 = new Helper_Survey("Service", serviceResult, overallServiceResult);
            output.add(temp3);
            Double overallResult = getOutletOverallResult(getOutletId(), month1, year);
            Double overallResultAll = sBean.getOverallAll(month1, year);
            Helper_Survey temp4 = new Helper_Survey("Overall", overallResult, overallResultAll);
            output.add(temp4);
            return output;
        }

        /**
         * @return the year
         */
        public Integer getYear() {
            return year;
        }

        /**
         * @param year the year to set
         */
        public void setYear(Integer year) {
            this.year = year;
        }

        /**
         * @return the resultList
         */
        public List<Double> getResultList() {
            return resultList;
        }

        /**
         * @param resultList the resultList to set
         */
        public void setResultList(List<Double> resultList) {
            this.resultList = resultList;
        }


        public Integer getMonth() {
            return month;
        }

        public void setMonth(Integer month) {
            this.month = month;
        }

        public Long getOutletId() {
            return (Long) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("outletId");
        }
        
        public void updateNumMonthToPred(ActionEvent event) {
    }

    }
